<?php

    #-------------------------------------------------------------#
	# This file is part of the Tekuna MVC Microframework for PHP. #
	# (c) 2009 Niels Jäckel <niels.jaeckel@tekuna.org>            #
	# Please visit http://tekuna.org/ for more information.       #
	#                                                             #
	# This software is licensed under the MIT License. Please     #
	# view the LICENSE file for the full text of this license.    #
    #-------------------------------------------------------------#


	Tekuna :: load('org.tekuna.core.filter.TekunaFilter');


	/**
	 * This filter limits input strings to a given maximum length. This
	 * can be used for such fields that allow a maximum characters count,
	 * e.g. postal code or length-delimited comments
	 */

	class LengthFilter implements TekunaFilter {

		protected $iMaxLenght = 0;


		/**
		 * Build a new LengthFilter with a certain maximum length
		 *
		 * @param int $iMaxLength the maximum character count
		 */

		public function __construct($iMaxLength) {

			$this -> iMaxLength = $iMaxLength;
		}


		/**
		 * Apply the filter
		 *
		 * @param mixed $mInput
		 * @return string
		 */

		public function filter($mInput) {

			// cut out only the first characters
			return substr($mInput, 0, $this -> iMaxLength);
		}
	}
